Skip to content

add unknown to DateTimeFormatTypes - #50402

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 3 commits into
microsoft:mainfrom
longlho:unknown
Aug 26, 2022
Merged

add unknown to DateTimeFormatTypes#50402
Daniel Rosenwasser (DanielRosenwasser) merged 3 commits into
microsoft:mainfrom
longlho:unknown

Conversation

@longlho

Copy link
Copy Markdown
Contributor

Fixes #50401

@typescript-bot

This comment was marked as resolved.

@typescript-bot TypeScript Bot (typescript-bot) added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug lib update PR modifies files in the `lib` folder labels Aug 22, 2022
@longlho

Copy link
Copy Markdown
Contributor Author

I removed the lib update

Comment thread package-lock.json Outdated
"dev": true,
"requires": {
"es5-ext": "0.10.53",
"es5-ext": "^0.10.50",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the package-lock.json changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup done!

@DanielRosenwasser

Copy link
Copy Markdown
Member

So ECMA-262 has a similar issue with typeof since hosts can introduce custom values with differing typeof behavior; however, TypeScript assumes that only the well-known built-in strings can be returned from typeof because it catches issues.

I'm not as familiar with the APIs here, so can you give an idea of how code is intended to handle something like this value? (maybe it can be used as a test-case)

@longlho

Long Ho (longlho) commented Aug 23, 2022

Copy link
Copy Markdown
Contributor Author

Daniel Rosenwasser (@DanielRosenwasser) yeah this is something different I believe that's not related to ecma262 typeof. The API here is that when you call new Intl.DateTimeFormat().formatToParts(new Date()) it returns a DateTimeFormatPart[] that has type & value. 1 of those types is called "unknown" (string literal, not related to TS unknown type).

See https://github.com/formatjs/formatjs/blob/main/packages/ecma402-abstract/types/date-time.ts#L187 for a reference. I do plan to backmerge formatjs types to TS cause the TS one is pretty outdated.

@DanielRosenwasser

Copy link
Copy Markdown
Member

Okay, I see, so it is classifying each portion of a date string (docs). Whatever it can't handle, it just classifies as unknown. That seems reasonable.

I guess the reason that we didn't have this is because the "unknown" type was added as a normative change in 2018 in tc39/ecma402#245. That means that it ended up in ECMA-402 2019. Given that, I unfortunately think that this needs to be added to a new lib file called es2019.intl.d.ts. 😫

@longlho

Copy link
Copy Markdown
Contributor Author

@DanielRosenwasser

Copy link
Copy Markdown
Member

It looks like you'll have to accept baselines - we baseline information about internal symbols which are unfortunately affected by changes to lib.d.ts ordering.

@longlho

Copy link
Copy Markdown
Contributor Author

What does that mean 😅 ?

@DanielRosenwasser

Copy link
Copy Markdown
Member

Oh, just run

npx gulp baseline-accept
git add tests/baselines/reference
git commit -m "Accepted baselines."

@DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) merged commit 71d1911 into microsoft:main Aug 26, 2022
@DanielRosenwasser

Copy link
Copy Markdown
Member

Thank you!

@longlho
Long Ho (longlho) deleted the unknown branch August 27, 2022 00:07
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug lib update PR modifies files in the `lib` folder

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing unknown in DateTimeFormatType

4 participants